package cn.youqu.happy.module.youqu.dal.mysql.userJoinActivity;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.userJoinActivity.vo.UserJoinActivityExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.userJoinActivity.vo.UserJoinActivityPageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userJoinActivity.UserJoinActivityDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户加入活动 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface UserJoinActivityMapper extends BaseMapperX<UserJoinActivityDO> {
    UserJoinActivityDO findOneByActivityIdAndHostUidAndUid(@Param("activityId") Integer activityId, @Param("hostUid") Long hostUid, @Param("uid") Long uid);


    int deleteByActivityIdAndHostUidAndUid(@Param("activityId") Integer activityId, @Param("hostUid") Long hostUid, @Param("uid") Long uid);

    List<UserJoinActivityDO> selectAllByActivityIdAndHostUid(@Param("activityId") Integer activityId, @Param("hostUid") Long hostUid);

    List<Long> selectUidByActivityIdAndHostUid(@Param("activityId") Integer activityId, @Param("hostUid") Long hostUid);


    default PageResult<UserJoinActivityDO> selectPage(UserJoinActivityPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserJoinActivityDO>()
                .eqIfPresent(UserJoinActivityDO::getUid, reqVO.getUid())
                .eqIfPresent(UserJoinActivityDO::getHostUid, reqVO.getHostUid())
                .eqIfPresent(UserJoinActivityDO::getActivityId, reqVO.getActivityId())
                .betweenIfPresent(UserJoinActivityDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserJoinActivityDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserJoinActivityDO::getId));
    }

    default List<UserJoinActivityDO> selectList(UserJoinActivityExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserJoinActivityDO>()
                .eqIfPresent(UserJoinActivityDO::getUid, reqVO.getUid())
                .eqIfPresent(UserJoinActivityDO::getHostUid, reqVO.getHostUid())
                .eqIfPresent(UserJoinActivityDO::getActivityId, reqVO.getActivityId())
                .betweenIfPresent(UserJoinActivityDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserJoinActivityDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserJoinActivityDO::getId));
    }

}
